home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / h / ATokenBuffer.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-14  |  3.1 KB  |  84 lines  |  [TEXT/MPS ]

  1. /* ANTLRTokenBuffer.h
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * ANTLR 1.23
  24.  * Terence Parr
  25.  * Parr Research Corporation
  26.  * with Purdue University and AHPCRC, University of Minnesota
  27.  * 1989-1994
  28.  */
  29.  
  30. #ifndef ATOKENBUFFER_H_GATE
  31. #define ATOKENBUFFER_H_GATE
  32.  
  33. #include "config.h"
  34. #include ATOKEN_H
  35. #include ATOKENSTREAM_H
  36. #include <stdlib.h>
  37.  
  38. /*
  39.  * The parser is "attached" to an ANTLRTokenBuffer via interface
  40.  * functions: getToken() and bufferedToken().  The object that actually
  41.  * consumes characters and constructs tokens is connected to the
  42.  * ANTLRTokenBuffer via interface function ANTLRTokenStream::getToken();
  43.  * where ANTLRTokenStream is really just a behavior (class with no data).
  44.  * C++ does not have this abstraction and hence we simply have come up
  45.  * with a fancy name for "void *".  See the note in ANTLRTokenStream.h on
  46.  * the "behavior" of ANTLRTokenStream.
  47.  */
  48.  
  49. class ANTLRTokenBuffer {
  50. protected:
  51.     ANTLRTokenStream *input;            // where do I get tokens
  52.     int buffer_size;
  53.     int chunk_size;
  54.     int num_markers;
  55.     int k;                              // Need at least this many tokens in buffer
  56.     ANTLRAbstractToken **buffer;        // buffer used for arbitrary lookahead
  57.     ANTLRAbstractToken **tp;            // pts into buffer; current token ptr
  58.     ANTLRAbstractToken **last;          // pts to last valid token in buffer
  59.     ANTLRAbstractToken **next;          // place to put next token from getANTLRToken()
  60.     ANTLRAbstractToken **end_of_buffer;
  61.  
  62.     // This function is filled in by the subclass; it initiates a fetch of input
  63.     virtual ANTLRAbstractToken *getANTLRToken() { return input->getToken(); }
  64.     void makeRoom();
  65.     void extendBuffer();
  66.  
  67. public:
  68.     ANTLRTokenBuffer(ANTLRTokenStream *in, int k=1, int chksz=200);
  69.  
  70.     virtual ~ANTLRTokenBuffer();
  71.     virtual ANTLRAbstractToken *getToken();
  72.     virtual void rewind(int pos);
  73.     virtual int mark();
  74.     virtual ANTLRAbstractToken *bufferedToken(int i);
  75.  
  76.     virtual bufferSize() { return buffer_size; }
  77.     virtual int minTokens() { return k; }
  78.     virtual void setMinTokens(int min) { k = min; }
  79.  
  80.     virtual void panic(char *msg) { exit(-1); }
  81. };
  82.  
  83. #endif
  84.